<?php

class WeChatValidation
{
    public function echoString() 
    {
        if(array_key_exists("echostr", $_GET)) 
        {
           return $_GET["echostr"];
        }

        return NULL;
    }

	public function checkSignature()
    {
        if(array_key_exists("signature", $_GET)) 
        {
            $signature = $_GET["signature"];
        } else 
        {
            $signature = "";
        }
        
        if(array_key_exists("timestamp", $_GET)) 
        {
            $timestamp = $_GET["timestamp"];
        } else 
        {
            $timestamp = "";
        }

        if(array_key_exists("nonce", $_GET))
        {
            $nonce = $_GET["nonce"];	
        } else
        {
            $nonce = "";	
        }
        		
		$token = TOKEN;
		$tmpArr = array($token, $timestamp, $nonce);
		sort($tmpArr, SORT_STRING);
		$tmpStr = implode( $tmpArr );
		$tmpStr = sha1( $tmpStr );
		
        if($tmpStr == $signature )
        {
			return true;
        }else
        {
			return false;
		}
	}
}

?>
